package com.evry.config;

import javax.sql.DataSource;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder;
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType;

import com.evry.repository.CollateralItemDao;
import com.evry.repository.CollateralItemDaoImpl;
import com.evry.repository.FractionsTest;
import com.evry.service.CollateralItemManager;
import com.evry.service.SimpleCollateralItemManager;
import com.evry.support.Fractions;

@Configuration
@Profile("dev")
public class AppDevConfig implements DataConfig {
    
    @Bean
    @Override
    public DataSource dataSource() {
        return new EmbeddedDatabaseBuilder()
                .setType(EmbeddedDatabaseType.HSQL)
                .addScript("/db/create-tables.sql")
                .addScript("/db/load-data.sql")
                .build();
    }
    
    @Bean
    public Fractions fractions(){
    	return new FractionsTest();
    }
    
    @Bean
    public CollateralItemDao collateralItemDao() {
        return new CollateralItemDaoImpl(dataSource());
    }
    
    @Bean
    public CollateralItemManager collateralItemManager() {
        return new SimpleCollateralItemManager();
    }
}
